package fatecpg.com.br.japassei;

/**
 * Created by MarcoAurélio on 28/11/2014.
 */
        import android.content.Context;
        import android.graphics.drawable.Drawable;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.Adapter;
        import android.widget.ArrayAdapter;
        import android.widget.ImageView;
        import android.widget.ListAdapter;
        import android.widget.TextView;

        import java.io.File;

/**
 * Created by MarcoAurélio on 13/11/2014.
 */
public class Adaptador {
    public ListAdapter adaptarUnicoIcone(Context contexto, CharSequence[] pItems, int pIcons)
    {
        final CharSequence[] items = pItems;
        final int icons = pIcons;
        final Context appContext = contexto;


        ListAdapter adapterMenu = new ArrayAdapter(appContext.getApplicationContext(), R.layout.list_row, items) {

            ViewHolder holder;
            Drawable icon;

            class ViewHolder {
                ImageView icon;
                TextView title;
            }

            public View getView(int position, View convertView,
                                ViewGroup parent) {
                final LayoutInflater inflater = (LayoutInflater) appContext.getSystemService(
                        Context.LAYOUT_INFLATER_SERVICE);

                if (convertView == null) {
                    convertView = inflater.inflate(
                            R.layout.list_row_file, null);

                    holder = new ViewHolder();
                    holder.icon = (ImageView) convertView
                            .findViewById(R.id.icon);
                    holder.title = (TextView) convertView
                            .findViewById(R.id.title);
                    convertView.setTag(holder);
                } else {
                    // view already defined, retrieve view holder
                    holder = (ViewHolder) convertView.getTag();
                }

                Drawable drawable = appContext.getResources().getDrawable(R.drawable.ic_disciplina); //this is an image from the drawables folder


                holder.title.setText(items[position]);
                File arquivo = new File(appContext.getFilesDir().getPath()+"/"+items[position]);
                holder.icon.setImageResource(icons);


                return convertView;
            }
        };

        return adapterMenu;
    }

    public ListAdapter adaptar(Context contexto, CharSequence[] pItems, int[] pIcons)
    {
        final CharSequence[] items = pItems;
        final int[] icons = pIcons;
        final Context appContext = contexto;


        ListAdapter adapterMenu = new ArrayAdapter(appContext.getApplicationContext(), R.layout.list_row, items) {

            ViewHolder holder;
            Drawable icon;

            class ViewHolder {
                ImageView icon;
                TextView title;
            }

            public View getView(int position, View convertView,
                                ViewGroup parent) {
                final LayoutInflater inflater = (LayoutInflater) appContext.getSystemService(
                        Context.LAYOUT_INFLATER_SERVICE);

                if (convertView == null) {
                    convertView = inflater.inflate(
                            R.layout.list_row, null);

                    holder = new ViewHolder();
                    holder.icon = (ImageView) convertView
                            .findViewById(R.id.icon);
                    holder.title = (TextView) convertView
                            .findViewById(R.id.title);
                    convertView.setTag(holder);
                } else {
                    // view already defined, retrieve view holder
                    holder = (ViewHolder) convertView.getTag();
                }

                //Drawable drawable = appContext.getResources().getDrawable(R.drawable.ic_disciplina); //this is an image from the drawables folder

                holder.title.setText(items[position]);
                holder.icon.setImageResource(icons[position]);
                //holder.icon.setImageDrawable(drawable);

                return convertView;
            }
        };

        return adapterMenu;
    }
}
